<template>
  <div class="app-container clearfix">  
    <div class="filter-container">
      <el-form ref="filterForm" :model="filterForm" :inline="true" label-position="left" label-width="100px">
        <el-form-item label="创建时间" prop="establishDates">
          <el-date-picker 
          clearable
            v-model="filterForm.establishDates"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="分组" prop="projectName">
          <el-input v-model="filterForm.projectName" clearable placeholder="项目编号/项目名称" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
        </el-form-item>
        <el-form-item label="销售代表" prop="industryID">
            <el-select v-model="filterForm.industryID" clearable placeholder="请选择">
              <el-option label="0" value="0">全部</el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="状态" prop="status">
            <el-select v-model="filterForm.status" clearable placeholder="请选择">
              <el-option label="0" value="0">全部</el-option>
              <el-option label="6" value="6">已处理</el-option>
              <el-option label="6" value="5">待处理</el-option>
              <el-option label="1" value="1">处理中</el-option>
            </el-select>
        </el-form-item>
      </el-form>
      <el-button  @click="onHandleCreated()">新建</el-button>
      <el-button  @click="getList()">搜索</el-button>
    </div>
      <el-table
      :data="list"
      border
      style="width: 100%">
    <el-table-column
     label="编号"
      type="selection"
      width="50">
    </el-table-column>
      <el-table-column
        label="文件名称" width="200">
        <template slot-scope="{row}">
          <div>{{ row.drainageName }}</div>
          <div>{{ row.drainageCode }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="文件简称">
        <template slot-scope="{row}">
          <div>{{ row.drainageName }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="标签">
        <template slot-scope="{row}">
          <el-tag
          v-for="label in row.labelList"
          :key="label.ID"
          handleRemoveLabel>
          {{label.labelName}}
        </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="销售代表">
        <template slot-scope="{row}">
          <el-tag
          v-for="employee in row.employeeList"
          :key="employee.ID"
          handleRemoveEmployee>
          {{employee.fullname}}
        </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="使用数量">
        <template slot-scope="{row}">
          <div>{{row.usableNum}}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="点击数量">
        <template slot-scope="{row}">
          <div>{{row.clickNum}}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="引流客户数量">
        <template slot-scope="{row}">
          <div>{{row.customerNum}}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="状态" width="100">
        <template slot-scope="{row}">
          <el-tag v-if="row.drainageStatus == 1" type="danger" effect="dark">待分配</el-tag>
          <el-tag v-else-if="row.drainageStatus == 2" type="warning" effect="dark">待处理</el-tag>
          <el-tag v-else-if="row.drainageStatus == 3" type="info" effect="dark">已作废</el-tag>
          <el-tag v-else-if="row.drainageStatus == 4" effect="dark">已添加</el-tag>
          <el-tag v-else effect="dark">未定义{{row.drainageStatus}}状态</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="作者" width="150">
        <template slot-scope="{row}">
          <div>{{ row.employee.fullname }}</div>
          <div>{{ row.createdAt }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="最后修改" width="150">
        <template slot-scope="{row}">
          <div>{{ row.updatedAt }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        width="400">
        <template slot-scope="{row}">
            <el-button v-if="row.scriptStatus == 2" type="text" @click="handleSubscribeCannel(row)" >取消</el-button>
            <el-button @click="handleSubscribeRemove(row)" >删除</el-button>
            <el-button @click="handleSubscribeChange(row)" >修改</el-button>
        </template>
      </el-table-column>
      </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="filterForm.page" :limit.sync="filterForm.size" @pagination="getList" />
  </div>
</template>

<script>
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import {getSymbol} from '@/utils/symbol' // secondary package based on el-pagination
import {getDrainageList} from '@/api/customer/drainage'



export default {
  name: 'financeDashboard',
  components: { Pagination },
  directives: { waves },
  filters: {
  },
  data() {
    return {
      
      socket:"",
      tableKey: 0,
      list: null,
      windowHeight:"600",
      total: 0,
      listLoading: false,
      documentationList:[],
      connected:"loading",
      timer:null,
      filterForm: {
        page: 1,
        size: 10,
        localSymbol:"",
        status:5,
        style:"0",
        keyword: undefined
      }
    }
  },
  created() {
    this.getList()
  },
  destroyed () {
      // 销毁监听
      this.close()
      clearInterval(this.timer)
      console.log("清除定时器")
  },
  methods: {
    getList:function(){
      let _this = this;
      console.log("期权",_this.filterForm)
      getDrainageList(_this.filterForm).then((response) => {
        console.log("getList",response)
          if (response.code === 200) {
            this.list = response.data.list
            this.total = response.data.total
          } else {
            _this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
    },
    onHandleCreated:function(){
      this.$router.push({ path: 'drainage-add'})

    },
    handleRemovedEmployee:function(){
      console.log("移除销售代表")
    },
    handleRemovedLable:function(){
      console.log("移除客户标签")
    },
    handleFilter() {
      this.filterForm.page = 1
      this.getList()
    },
    sortChange:function(){

    }
  }
}
</script>
<style>
.filter { float: left; width: 160px; padding: 20px; min-height: 600px; }
.article { float: left; width: 800px; }
.article-item { width: 800px; height: 200px; margin-right: 25px; }
.article-item-text { float: left; width:600px; }
.article-item-icon { float: right; width:200px; height:150px; padding-left: 50px; }
.article-item-icon img { width:100%; height:100%; border-radius: 10px; }
</style>